package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppHelp;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author anxiang
 * @version 1.0.0
 * @ClassName AfterHelpServiceDao.java
 * @Description 帮助列表
 * @createTime 2021年07月23日 12:54:00
 */
@Repository
public class AfterHelpServiceDao extends BaseDao<AppHelp> {

    /**
     * 新增或更新
     *
     * @param appHelp
     */
    public void saveOrUpdate(AppHelp appHelp) {
        if (appHelp.getId() == null || appHelp.getId() == 0) {
            appHelp.setId(this.add(appHelp));
        } else {
            this.update(appHelp);
        }
    }

    /**
     * 综合查询列表
     *
     * @param paramap
     * @param splitPageBean
     * @return
     */
    public List<AppHelp> findList(Map<String, Object> paramap, SplitPageBean splitPageBean) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_help where 1=1 ");
        if (StringEx.isNotNull(paramap.get("biaoti"))) {
            str.append(" and biaoti like ? ");
            list.add("%"+paramap.get("biaoti")+"%");
        }
        String sql = str.toString();
        return this.queryList(sql, list, AppHelp.class, splitPageBean);
    }

    /**
     * 查询
     *
     * @return
     */
    public AppHelp get(Integer id) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("select * from app_help where 1=1 ");
        str.append(" and id = ? ");
        list.add(id);

        String sql = str.toString();
        return this.queryObj(sql, list, AppHelp.class);
    }

    /**
     * 更新显示的状态
     *
     * @param id
     * @param status
     */
    public void updateStatus(Integer id, Integer status) {
        List<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("update app_help set status = ? where id = ? ");
        list.add(status);
        list.add(id);
        String sql = str.toString();
        this.update(sql, list);
    }

    /**
     * 删除
     *
     * @param id
     */
    public void delete(Integer id) {
        ArrayList<Object> list = new ArrayList<>();
        StringBuilder str = new StringBuilder("");
        str.append("delete from app_help where id = ? ");
        list.add(id);
        String sql = str.toString();
        this.del(sql, list);
    }


}